﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MCWEBSITE.BUL;

public partial class Modules_HugKid_wucListCart : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Cookies["MCMPlaylist"] == null || Request.Cookies["MCMPlaylist"].ToString() == "")
        {
            //no record
            DataBind(null);
            lblEmptyText.Text = "Chưa có sản phẩm nào!!!";
        }
        else
        {
            lblEmptyText.Text = "";
            HttpCookie cookie = Request.Cookies["MCMPlaylist"];
            cookie.Expires = DateTime.MaxValue;// Never Expires
            string strCookie = Request.Cookies["MCMPlaylist"].Value.ToString().Replace("%7C", "|");
            string[] strvalue = strCookie.Split('|');
            DataBind(strvalue);
        }
    }

    protected void DataBind(string[] strvalue)
    {
        if (strvalue != null)
        {
            dlListCart.Visible = true;
            DataSet PlayList = DataPlayList(strvalue);

            dlListCart.DataSource = PlayList;
            dlListCart.DataBind();
        }
        else
        {           
            dlListCart.Visible = false;
        }
    }

    public DataSet DataPlayList(string[] strvalue)
    {
        DataSet ds = new DataSet();
        DataTable dt = new DataTable();
        dt.Columns.Add("ItemID", Type.GetType("System.String"));
        dt.Columns.Add("ItemName", Type.GetType("System.String"));
        dt.Columns.Add("Atribute2", Type.GetType("System.String"));//anh dai dien
        dt.Columns.Add("Atribute1", Type.GetType("System.String"));//price cua san pham
        ds.Tables.Add(dt);
        for (int i = 0; i < strvalue.Length; i++)
        {
            if (strvalue[i].ToString() != "")
            {
                DataRow dr;
                dr = dt.NewRow();
                dr["ItemID"] = strvalue[i].ToString();
                DataSet objDataset = new DataSet();
                //objDataset = PresentationDetailBUL.GetPresentationDetailById(Convert.ToInt32(strvalue[i].ToString()), "300x300");
                objDataset = websiteProductBUL.GetDetails(Convert.ToInt32(strvalue[i].ToString()));
                if (objDataset!= null && objDataset.Tables[0].Rows.Count > 0)
                {
                    dr["ItemName"] = objDataset.Tables[0].Rows[0]["ItemName"].ToString();
                    dr["Atribute1"] = objDataset.Tables[0].Rows[0]["Atribute1"].ToString();
                    dr["Atribute2"] = objDataset.Tables[0].Rows[0]["Atribute2"].ToString();
                    dt.Rows.Add(dr);
                }
            }
        }

        ds.AcceptChanges();
        return ds;
    }
}
